package com.stormrage.edu.serv.student.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stormrage.edu.dao.student.StuNoticeDao;
import com.stormrage.edu.serv.student.StuNoticeServ;
import com.stormrage.entity.student.StuNotice;
import com.stormrage.entity.student.rep.StuNoticeRep;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: StuNoticeServImpl.java
 * @Package com.stormrage.edu.serv.student.impl
 * @Description: 通知 Service
 * @author www.stormragetech.com
 * @date 2016年4月18日
 * @version V1.0
 */
@Service
public class StuNoticeServImpl implements StuNoticeServ {

	private static final Logger logger = LoggerFactory.getLogger(StuNoticeServImpl.class);

	@Autowired
	private StuNoticeDao stuNoticeDao;

	@Override
	public Integer create(final StuNotice arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 create 】-【 STARTED 】");

		Integer index = stuNoticeDao.create(arg0);

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 create 】-【 COMPLETED 】");
		return index;

	}

	@Override
	public void update(final StuNotice arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 update 】-【 STARTED 】");

		stuNoticeDao.update(arg0);

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 update 】-【 COMPLETED 】");

	}

	@Override
	public Integer queryCountByBunchId(final Integer arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 queryCountByBunchId 】-【 STARTED 】");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("bunchId", arg0);

		Integer count = stuNoticeDao.queryCountByBunchId(map);

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 queryCountByBunchId 】-【 COMPLETED 】");
		return count;

	}

	@Override
	public StuNotice queryById(final Integer arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 QueryById 】-【 STARTED 】");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", arg0);

		StuNotice entity = stuNoticeDao.queryById(map);

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 QueryById 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public List<StuNotice> queryListByBunchId(final Integer arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 QueryListByBunchId 】-【 STARTED 】");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("bunchId", arg0);

		List<StuNotice> array = stuNoticeDao.queryListByBunchId(map);

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 QueryListByBunchId 】-【 COMPLETED 】");
		return array;

	}

	@Override
	public List<StuNoticeRep> queryRepListByBunchId(final Integer arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 queryRepListByBunchId 】-【 STARTED 】");

		List<StuNotice> array = queryListByBunchId(arg0);

		List<StuNoticeRep> list = new ArrayList<StuNoticeRep>();
		int seq = 1;

		Iterator<StuNotice> it = array.iterator();
		while (it.hasNext()) {
			StuNotice notice = it.next();
			StuNoticeRep rep = StuNoticeRep.instance(notice, seq);
			list.add(rep);
			seq++;
		}

		logger.debug(" 【 Serv 】- 【 StuNoticeServ 】- 【 queryRepListByBunchId 】-【 COMPLETED 】");
		return list;

	}

}
